/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.broker.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import me.send.broker.entity.Message;

/**
 * @author maxmin
 *
 * @date 2015年8月25日 下午2:07:54
 */
public interface MessageMapper {

	/**
	 * 添加消息记录
	 * 
	 * @param message
	 * @return
	 */
	@Insert(value = "INSERT INTO message (message,user_id,user_type,type,orderid,from_user_id,createtime,updatetime) "
			+ "values (#{message},#{userId},#{userType},#{type},#{orderId},#{fromUserId},#{createtime},#{updatetime})")
	public int addMessage(Message message);

	/**
	 * 获取通知消息列表
	 * 
	 * @param brokerid
	 * @return
	 * @author maxmin
	 * @date 2015年8月27日上午11:42:34
	 */
	@Select(value = "SELECT m.message_id,m.message,m.createtime,m.type,m.orderid FROM message m WHERE m.user_id=#{brokerid} "
			+ "AND m.user_type=2 AND m.type=1 AND IF (#{startid}>0,m.message_id<#{startid},1=1) ORDER BY m.message_id DESC Limit #{size}")
	@Results({ @Result(column = "message_id", property = "messageId"),
			@Result(column = "orderid", property = "orderId") })
	public List<Message> getMessagesByBrokerId(Map<String, Object> params);

	/**
	 * 获取活动消息列表 包括 点赞或者评论
	 * 
	 * @param brokerid
	 * @return
	 * @author maxmin
	 * @date 2015年8月27日上午11:42:34
	 */
	@Select(value = "SELECT m.message_id,m.message,m.createtime,m.type,m.orderid,u.headerpath,u.nickname FROM message m "
			+ "LEFT JOIN `user` u ON m.from_user_id=u.userid WHERE m.user_id=#{brokerid} "
			+ "AND m.user_type=2 AND m.type>1 AND IF (#{startid}>0,m.message_id<#{startid},1=1) ORDER BY m.message_id DESC Limit #{size}")
	@Results({ @Result(column = "message_id", property = "messageId"),
			@Result(column = "orderid", property = "orderId") })
	public List<Message> getDynamicMessagesByBrokerId(Map<String, Object> params);
}
